﻿using System.Text;
using System.Windows.Forms;
using Me.Amon.POS.M;
using Me.Amon.Util;
using System;

namespace Me.Amon.POS.V.SO
{
    public partial class UcVip : UserControl
    {
        private MVip _DefVip;

        public UcVip()
        {
            InitializeComponent();
        }

        public MVip CurrentVip { get; private set; }

        public void ShowVip()
        {
            if (_DefVip == null)
            {
                _DefVip = new MVip();
                _DefVip.id = "";
                _DefVip.code = "A0000000";
                _DefVip.level = 0;
            }
            ShowVip(_DefVip);
        }

        public void ShowVip(MVip vip)
        {
            CurrentVip = vip;

            if (!string.IsNullOrEmpty(vip.last_name))
            {
                LdName.Text = vip.last_name + MVip.GetSex(vip.sex);
            }
            else if (!string.IsNullOrEmpty(vip.display_name))
            {
                var buf = new StringBuilder();
                buf.Append(vip.display_name[0]);
                for (int i = 0; i < vip.display_name.Length - 1; i += 1)
                {
                    buf.Append('*');
                }
                LdName.Text = buf.ToString();
            }
            else
            {
                LdName.Text = "客户";
            }

            LdLevel.Text = vip.level.ToString();

            LdPoint.Text = vip.point.ToString();

            if (vip.IsBirthday())
            {
                // 提示生日
                LdNotice.Text = "今天是您的生日！";
            }
            else
            {
                LdNotice.Text = "";
            }
        }

        public void ShowPay()
        {
            LdSoCode.Text = "";
            LdRpay.Text = "0";
            LdXpay.Text = "0";
        }

        public void ShowPay(MSoHeader soHeader)
        {
            LdSoCode.Text = soHeader.code;
            LdAmount.Text = CharUtil.FormatPrice(soHeader.round_amount);
            LdRpay.Text = CharUtil.FormatPrice(soHeader.prepay_amount);
            LdXpay.Text = CharUtil.FormatPrice(soHeader.change_amount);
        }
    }
}
